package core.views;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import core.Runner;
import core.models.Paces;
import core.models.Rations;

/**
 * Displays the primary option screen.
 * 
 * @author 4c1a
 */
@SuppressWarnings("serial")
public class OptionsPanel extends JPanel {
	private JTextField paceField;
	private JTextField rationField;
	private Runner runner;
	
	private JComboBox foodRationsComboBox;
	private JComboBox paceComboBox;
	
	/**
	 * Brings up a screen that allows the player to set rations and pace.
	 * 
	 * @param runner The runner to be used by this panel.
	 */
	public OptionsPanel(Runner runner) {
		setLayout(null);
		this.runner = runner;
		
		paceField = new JTextField();
		paceField.setEditable(false);
		paceField.setBorder(null);
		paceField.setText("Pace:");
		paceField.setBounds(10, 11, 86, 20);
		add(paceField);
		paceField.setColumns(10);
		
		paceComboBox = new JComboBox();
		paceComboBox.setModel(new DefaultComboBoxModel(Paces.values()));
		paceComboBox.setBounds(105, 12, 86, 20);
		add(paceComboBox);
		
		rationField = new JTextField();
		rationField.setBorder(null);
		rationField.setText("Rations:");
		rationField.setEditable(false);
		rationField.setColumns(10);
		rationField.setBounds(10, 42, 91, 20);
		add(rationField);
		
		foodRationsComboBox = new JComboBox();
		foodRationsComboBox.setModel(new DefaultComboBoxModel(Rations.values()));
		foodRationsComboBox.setBounds(105, 42, 86, 20);
		add(foodRationsComboBox);
	}
	
	/**
	 * Loads the data for combo boxes.
	 */
	public void loadData() {
		paceComboBox.setSelectedItem(runner.getGroup().getWagon().getPace());
		foodRationsComboBox.setSelectedItem(runner.getGroup().getRation());
	}

	/**
	 * Updates the pace and rations for the group.
	 */
	public void update() {
		runner.getGroup().getWagon().setPace((Paces) paceComboBox.getSelectedItem());
		runner.getGroup().setRation((Rations) foodRationsComboBox.getSelectedItem());
		System.out.println(runner.getGroup());
		System.out.println(runner.getGroup().getWagon());
	}
	

}
